package ModLayer;
import java.util.ArrayList;

/**
 * Write a description of class ProductCon here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class ProductCon
{
    public static ProductCon instance;
    ArrayList<Product> productList;
    
    private ProductCon()
    {
        productList = new ArrayList<Product>();
    }

    public static ProductCon getInstance()
    {
        if(instance==null)
            instance = new ProductCon();
        return instance;
    }

    public void createProduct(String name,String id, String description, boolean sell, 
    boolean lease, double price, double leaseprice, int stockDIY, int stockBath, int stockKit)
    {
        Product product = new Product(name, id, description, sell, lease, 
        price, leaseprice, stockDIY, stockBath, stockKit);
        productList.add(product);
    }

    public void deleteProduct(Product product)
    {
        productList.remove(product);
    }

    public Product findProduct(String id)
    {
        Product returnProduct=null;
        for(Product x : productList)
        {
            if(id.equals(x.getID()))
            {
                returnProduct = x;
            }
        }
        return returnProduct;
    }

    public Product findProductn(String id)
    {
        Product returnProduct=null;
        for(Product x : productList)
        {
            if(id.equals(x.getName()))
            {
                returnProduct = x;
            }
        }
        return returnProduct;
    }

    public ArrayList<Product> searchProduct()
    {
        ArrayList<Product> returnProduct= new ArrayList<Product>();
        for(Product x : productList)
        {
            returnProduct.add(x);
        }
        return returnProduct;
    }

    public void updateProduct(int stock, int stockDYI, int stockBath, int stockKit, String description, 
    boolean sell, boolean lease, double price, double leaseprice, Product p)
    {
        p.setStockDIY(stockDYI);
        p.setStockBath(stockBath);
        p.setStockKit(stockKit);
        p.setSellable(sell);
        p.setLeaseable(lease);
        p.setDescription(description);
        p.setPrice(price);
        p.setLeasePrice(leaseprice);
    }
}